/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Data.ActivityLog;

import CrlException.CrlException;
import Control.MainControl.MainControl;

/**
 *
 * @author CUHUUHOANG
 */
public class StatisticUtility {

    private static String allLog;
    private static long startTime;
    private static long totalTime;
    public static boolean isStopped;

    public StatisticUtility() throws CrlException {
        try {
            allLog = new String();
            isStopped = true;
            totalTime = 0;
        } catch (Exception e) {
            throw new CrlException(e.getMessage());
        }
    }

    public static int getURLQueued() throws CrlException {
        try {
            return Data.Frontier.URLCrl.urlDT.getSize();
        } catch (Exception e) {
            throw new CrlException(e.getMessage());
        }
    }

    public static int getURLProcessed() throws CrlException {
        try {
            return Data.Frontier.URLCrl.urlDT.getURLProcessed();
        } catch (Exception e) {
            throw new CrlException(e.getMessage());
        }
    }

    public static int getThreadRunning() throws CrlException {
        try {
            return MainControl.ProcessManager.getSize();
        } catch (Exception e) {
            throw new CrlException(e.getMessage());
        }
    }

    public static float getDownloadSpeed() throws CrlException {
        try {
            return 0;
        } catch (Exception e) {
            throw new CrlException(e.getMessage());
        }
    }

    public static String getTime() throws CrlException {
        try {
            int second = (int) getTimeOrigin() / 1000;
            return (int) second / 60 + ": " + second % 60;
        } catch (Exception e) {
            throw new CrlException(e.getMessage());
        }
    }

    public static String getLog() throws CrlException {
        try {
            String newLog = null;
            do {
                newLog = ActivityCrl.atiData.getAtivity();
                if (newLog != null) {
                    allLog += newLog + "\r\n";
                }
            } while (newLog != null);
            return allLog;
        } catch (Exception e) {
            throw new CrlException(e.getMessage());
        }
    }

    public static void setStop() throws CrlException {
        try {
            if (!isStopped) {
                totalTime += System.currentTimeMillis() - startTime;
            }
        } catch (Exception e) {
            throw new CrlException(e.getMessage());
        }
    }

    public static void setStart() throws CrlException {
        try {
            startTime = System.currentTimeMillis();
        } catch (Exception e) {
            throw new CrlException(e.getMessage());
        }
    }

    public static long getTimeOrigin() throws CrlException {
        try {
            if (isStopped) {
                return totalTime;
            } else {
                return totalTime + System.currentTimeMillis() - startTime;
            }
        } catch (Exception e) {
            throw new CrlException(e.getMessage());
        }
    }
}
